package com.example.xianglilai_end.Controller;

import com.alibaba.fastjson.JSONObject;
import com.example.xianglilai_end.Bean.*;
import com.example.xianglilai_end.Mapper.StationsMapper;
import com.example.xianglilai_end.Service.BatteriesService;
import com.example.xianglilai_end.Service.StationsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;

@RestController
public class BatteriesController {
    @Autowired
    BatteriesService batteriesService;  // 自动注入BatteriesService

    @CrossOrigin
    @GetMapping ("api/battery/getBatteryGpsList")
    /* 获取15分钟内所有电池的GPS列表和对应的timeline */
    public BatteryGpsList getBatteryGpsList(@RequestParam("day")int day, @RequestParam("start")int start_time, @RequestParam("end")int end_time){
        return batteriesService.getBatteriesGPS_15min(day, start_time, end_time);
    }

    @CrossOrigin
    @GetMapping("api/battery/detail")
    /* 获取电池详细信息 */
    public BatteryDetails getBatteryDetails(@RequestParam("device_id")int device_id, @RequestParam("time")int time){
        return batteriesService.getBatteryDetails(device_id, time);
    }

    @CrossOrigin
    @GetMapping("api/battery/state")
    public BatteryState getBatteryState(@RequestParam("time") int time){
        return batteriesService.getBatteryState(time);
    }

    @CrossOrigin
    @GetMapping("api/battery/area")
    public BatteryAreaNum getAreaRand(@RequestParam("day")int day, @RequestParam("time")int time) throws IOException {
        return batteriesService.getAreaRank(day, time);
    }

    //只根据一天的GPS表计算区域数量
    @CrossOrigin
    @GetMapping("api/battery/areanum")
    public BatteryAreaNum getAreanum(@RequestParam("day")int day) throws IOException {
        return batteriesService.getAreaNum(day);
    }

    @CrossOrigin
    @GetMapping("api/battery/usage")
    public int getBatteryUsage(){
        return batteriesService.getBatteryCapacityMonth();
    }
}
